using strange.extensions.mediation.impl;
using UnityEngine;

namespace CounterApp.StrangeIOC
{
    public class BtnAddViewMediator : EventMediator
    {
        [Inject] 
        public BtnAddView BtnAddView { get; set; }
        
        public override void OnRegister()
        {
            // 在这里进行 View 的初始化
            BtnAddView.Init();
            
            // 从 View 注册按钮事件
            BtnAddView.dispatcher.AddListener(BtnAddView.CLICK_EVENT,OnBtnAddViewClick);
        }

        /// <summary>
        /// 实现按钮点击事件
        /// </summary>
        void OnBtnAddViewClick()
        {
            // 发送事件给 Controller 层
            dispatcher.Dispatch(IncreaseCommand.EVENT);
        }

        public override void OnRemove()
        {
            // 从 View 注销按钮点击事件
            BtnAddView.dispatcher.RemoveListener(BtnAddView.CLICK_EVENT,OnBtnAddViewClick);
        }
    }
}